//
//  PersonHeaderView.m
//  兼职页面
//
//  Created by kuiyuan liang on 2021/5/25.
//

#import "PersonHeaderView.h"
#import "CommonUtil.h"

@interface PersonHeaderView()

@property (strong, nonatomic) UIImageView * bgImageView;
@property (strong, nonatomic) UILabel * titleLabel;

@property (strong, nonatomic) UIView * whiteView;
@property (strong, nonatomic) UIImageView * iconImageView;
@property (strong, nonatomic) UIButton * followBtn;
@property (strong, nonatomic) UILabel * nickLabel;
@property (strong, nonatomic) UILabel * vipLabel;
@property (strong, nonatomic) UILabel * subTitleLabel;

@end

@implementation PersonHeaderView




-(instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
     
        self.backgroundColor = RGB(243.0, 243.0, 243.0);
        [self addSubview:self.bgImageView];
        [self addSubview:self.titleLabel];
        [self addSubview:self.backBtn];
        [self addSubview:self.whiteView];
        [self.whiteView addSubview:self.iconImageView];
        [self.whiteView addSubview:self.followBtn];
        [self.whiteView addSubview:self.nickLabel];
        [self.whiteView addSubview:self.vipLabel];
        [self.whiteView addSubview:self.subTitleLabel];
        

         UIImage *image = [UIImage imageNamed:@"icon_vip"];
        [CommonUtil setText:@"" frontImages:@[image,image,image,image] imageSpan:AD(3) label:self.vipLabel];
    }
    return self;
}




- (void)followBtnClick:(UIButton *)sender{
    sender.selected = !sender.selected;
    if (sender.selected) {
        sender.backgroundColor = RGB(243.0, 243.0, 243.0);
       
    }else{
        sender.backgroundColor = RGB(255.0, 105.0, 33.0);
    }
    NSLog(@"关注");
}

#pragma mark -lazy
-(UIImageView *)bgImageView{
    if (!_bgImageView) {
        _bgImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"forum_bg.jpg"]];
        _bgImageView.frame = CGRectMake(0, 0, SCREEN_WIDTH, AD(200));
    }
    return _bgImageView;
}

-(UIButton *)backBtn{
    if (!_backBtn) {
        _backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_backBtn setImage:[UIImage imageNamed:@"icon_back"] forState:UIControlStateNormal];
        [_backBtn setTitle:@"返回" forState:UIControlStateNormal];
        [_backBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _backBtn.frame = CGRectMake(AD(10), kStatusBarHeight + AD(7), AD(60), AD(30));
        _backBtn.imageEdgeInsets = UIEdgeInsetsMake(0, AD(-15), 0, 0);
    }
    return _backBtn;
}

-(UILabel *)titleLabel{
    if (!_titleLabel) {
        _titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, kStatusBarHeight, SCREEN_WIDTH, 44)];
        _titleLabel.text = @"留言板";
        _titleLabel.textColor = [UIColor whiteColor];
        _titleLabel.font = [UIFont systemFontOfSize:AD(16)];
        _titleLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _titleLabel;
}

-(UIView *)whiteView{
    if (!_whiteView) {
        _whiteView = [[UIView alloc] initWithFrame:CGRectMake(AD(15), AD(120), SCREEN_WIDTH-AD(30), AD(120))];
        _whiteView.backgroundColor = [UIColor whiteColor];
        _whiteView.layer.cornerRadius= AD(5);
        _whiteView.layer.shadowColor = [UIColor blackColor].CGColor;
        _whiteView.layer.shadowRadius= AD(3);
        _whiteView.layer.shadowOpacity = 0.3f;
        _whiteView.layer.shadowOffset = CGSizeMake(0,0);
    }
    return _whiteView;
}

-(UIImageView *)iconImageView{
    if (!_iconImageView) {
        _iconImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"statistics_default.jpg"]];
        _iconImageView.frame = CGRectMake(AD(10), AD(-20), AD(70), AD(70));
        _iconImageView.layer.cornerRadius = AD(35);
        _iconImageView.clipsToBounds = YES;
    }
    return _iconImageView;
}

-(UIButton *)followBtn{
    if (!_followBtn) {
        _followBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_followBtn setTitle:@"+ 关注" forState:UIControlStateNormal];
        [_followBtn setTitle:@"已关注" forState:UIControlStateSelected];
        [_followBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [_followBtn setTitleColor:[UIColor lightGrayColor] forState:UIControlStateSelected];
        _followBtn.frame = CGRectMake(_iconImageView.right + AD(10), AD(10), AD(150), AD(35));
        _followBtn.backgroundColor = RGB(255.0, 105.0, 33.0);
        [_followBtn addTarget:self action:@selector(followBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        _followBtn.layer.cornerRadius = AD(17.5);
        _followBtn.clipsToBounds = YES;
        _followBtn.titleLabel.font = [UIFont systemFontOfSize:AD(15)];
        
    }
    return _followBtn;
}

-(UILabel *)nickLabel{
    if (!_nickLabel) {
        _nickLabel = [[UILabel alloc] initWithFrame:CGRectMake(_iconImageView.left, _iconImageView.bottom + AD(10), AD(100), AD(30))];
        _nickLabel.text = @"合家欢喜";
        _nickLabel.textColor = [UIColor blackColor];
        _nickLabel.font = [UIFont boldSystemFontOfSize:AD(15)];
    }
    return _nickLabel;
}

-(UILabel *)vipLabel{
    if (!_vipLabel) {
        _vipLabel = [[UILabel alloc] initWithFrame:CGRectMake(_nickLabel.right, _nickLabel.top, self.whiteView.width-_nickLabel.right, _nickLabel.height)];
    }
    return _vipLabel;
}

-(UILabel *)subTitleLabel{
    if (!_subTitleLabel) {
        _subTitleLabel = [[UILabel alloc] initWithFrame:CGRectMake(_iconImageView.left, _nickLabel.bottom, self.whiteView.width-AD(20), AD(20))];
        _subTitleLabel.text = @"这个人很懒,他什么也没说...";
        _subTitleLabel.textColor = [UIColor lightGrayColor];
        _subTitleLabel.font = [UIFont systemFontOfSize:AD(13)];
    }
    return _subTitleLabel;
}




@end
